#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
struct network{
	string x;
	int a;
	int b;
	int c;
	int d;
	int e;
	char f1;
	char f2;
	char f3;
	char f4;
	int h;
}a[1001];
int main()
{
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].x>>a[i].a>>a[i].f1>>a[i].b>>a[i].f2>>a[i].c>>a[i].f3>>a[i].d>>a[i].f4>>a[i].e;
		if(a[i].a<=255&&a[i].b<=255&&a[i].c<=255&&a[i].d<=255&&a[i].e<=65535&&a[i].f1=='.'&&a[i].f2=='.'&&a[i].f3=='.'&&a[i].f4==':'){
				if(a[i].x=="Client") a[i].h=1;
			else
			{
				if(i==1) a[i].h=i;
				else{
					for(int l=1;l<i;l++){
		if(a[l].x=="Server"&&a[i].a==a[l].a&&a[i].b==a[l].b&&a[i].c==a[l].c&&a[i].d==a[l].d&&a[i].e==a[l].e)	
		{
			a[i].h=1002;break;
		}
		if(l+1==i) a[i].h=i;
				}
				
			}
			}
			
		}
		else a[i].h=0;
	}
	for(int i=1;i<=n;i++)
	cout<<a[i].h<<" ";
	cout<<endl;
	for(int i=1;i<=n;i++)
	{
		cout<<i<<".";
		if(a[i].x=="Server")
		{
			if(a[i].h==0)
			cout<<"ERR"<<endl;
			if(a[i].h==1002)
			cout<<"FAIL"<<endl;
			if(a[i].h!=0&&a[i].h!=1002)
			cout<<"OK"<<endl;
		 } 
		 else
		 {
		 	if(a[i].h!=0)
		 	{
		 		if(a[i].h==1&&i==1)
		 			{ cout<<"FAIL";}
		 			else
		 		for(int j=1;j<i;j++)
		 	{
		 		if(a[j].x!="Client")
		 		{
		 			if(a[j].h!=0&&a[j].h!=1002&&a[i].a==a[j].a&&a[i].b==a[j].b&&a[i].c==a[j].c&&a[i].d==a[j].d&&a[i].e==a[j].e)
		 			{
		 				cout<<a[j].h<<endl;
		 				break;
					 }
					
				 }
				  if(j==i-1) cout<<"FAIL"<<endl;
			 }
			 }
		 	else
		 	cout<<"ERR"<<endl;
		 }
	}
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}
